package com.wanmait.schedule.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanmait.schedule.entity.Company;
import com.wanmait.schedule.entity.CompanyUser;
import com.wanmait.schedule.entity.Department;
import com.wanmait.schedule.mapper.DepartmentMapper;
import com.wanmait.schedule.service.CompanyService;
import com.wanmait.schedule.service.DepartmentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.nio.file.Path;
import java.util.List;
import java.util.Queue;

/**
 * <p>
 * 部门表 服务实现类
 * </p>
 *
 * @author wanmait
 * @since 2022-03-02
 */
@Service
public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Department> implements DepartmentService {

    @Resource
    CompanyService companyService;
    @Resource
    DepartmentMapper departmentMapper;

    @Override
    public PageInfo<Department> findPage(Integer pageNum, Integer pageSize,Integer companyId) {
        PageHelper.startPage(pageNum,pageSize);
        LambdaQueryWrapper<Department> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Department::getCompanyId,companyId);
        List<Department> departments = this.list(queryWrapper);
        departments.forEach(department -> {
            department.setCompany(companyService.getById(department.getCompanyId()));
        });
        PageInfo<Department> pageInfo = new PageInfo<>(departments);
        return pageInfo;
    }

    @Override
    public List<Department> initDepartment(Integer companyId) {
        LambdaQueryWrapper<Department> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Department::getCompanyId,companyId);
        List<Department> departments = departmentMapper.selectList(queryWrapper);
        return departments;
    }
}
